<?php
/**
* Class Proveedor.
*
* Implementation of the class Permiso.
*
* PHP version >= 5.1
*
* @category     FrameworkPunkuPHP
* @package      Model
* @author       Juan Carlos Torrico Rios
* @copyright    2010 Juan Carlos Torrico Rios
* @license      http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version      1.0
* @link         None
* @see          None
* @since        Available from the version  0.1 01-01-2010
* @deprecated   No
*/

/**
* Class Proveedor
*
* Implementation of class Permiso.
*
* @category   WindowSI
* @package    Model
* @author     Juan Carlos Torrico Rios
* @copyright  2010 Juan Carlos Torrico Rios
* @license    http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version    1.0
* @link       None
* @see        None
* @since      Available from the version  0.1 01-01-2010
* @deprecated No
*/
    class Proveedor {
     // {{{ Constants

    /**
     * Constant for represent all registers.
     *
     * @access private
     */
     const ALL = -1;
     const VALUE = 1;
     const NONE = 0;
     // Operations
     const INSERT = "INSERT TABLE ALM_PROVEEDOR";
     const UPDATE = "UPDATE TABLE ALM_PROVEEDOR";
     const DELETE = "DELETE TABLE ALM_PROVEEDOR";
     const SELECT = "SELECT TABLE ALM_PROVEEDOR";
    // }}}

    // {{{ atributos

    /**
     * Variable instance Data Base.
     *
     * @var DataBase
     * @access private
     */
        private  $instanceDataBase;
    // }}}

    // {{{ constructores

    /**
     * This is construct base of the class.
     *
     * A public constructor; initializes the variable $instanceDataBase.
     *
     */
        public function __construct( $instanceDataBase ) {
            $this->instanceDataBase = $instanceDataBase;
        }
    // }}}

    // {{{ metodos

    /**
     * The implementation method for query to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function getListProveedor($idProveedor = self::ALL){
            $result = null;
            $query = null;
            try{
                $query = "SELECT pk_id_proveedor, 
                                 codigo, 
                                 nit,
                                 razon_social, 
                                 direccion, 
                                 telefono1, 
                                 telefono2, 
                                 telefono3, 
                                 contacto, 
                                 fk_id_rubro, 
                                 fk_id_ubicacion_geografica, 
                                 fecha1, 
                                 fecha2, 
                                 texto1, 
                                 texto2, 
                                 fecha_transaccion, 
                                 usuario_transaccion, 
                                 estado_registro, 
                                 transaccion_creacion, 
                                 transaccion_modificacion,
                                 fk_id_empresa 
                           FROM   alm_proveedor 
                           WHERE  estado_registro = 'A' ";

                if( $idProveedor != self::ALL){
                $query = $query." AND pk_id_proveedor = ?";
                $result = DataBase::getArrayListQuery($query, array($idProveedor), $this->instanceDataBase);
                }
                else{
                $result = DataBase::getArrayListQuery($query,array(), $this->instanceDataBase);
                }
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0941: '.$e->getMessage();
            }
            return $result;
        }

    /**
     * The implementation method for insert data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function insertProveedor($data){
            $result = null;
            $query = null;
            try{
                $query = "INSERT INTO 
                 alm_proveedor( codigo, 
		 nit,
                 razon_social, 
		 direccion, 
		 telefono1, 
		 telefono2, 
		 telefono3, 
		 contacto, 
                 fk_id_rubro, 
		 fk_id_ubicacion_geografica, 
		 fecha1, 
		 fecha2, 
		 texto1, 
		 texto2, 
                 fecha_transaccion, 
		 usuario_transaccion, 
		 estado_registro, 
		 transaccion_creacion, 
		 transaccion_modificacion,
                 fk_id_empresa ) ".
                         "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, current_timestamp(), ?, 'A', ?, ?, ?)";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0932: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for delete data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function deleteProveedor($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_proveedor ".
                         "SET estado_registro = 'E', ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ? ".
                         "WHERE pk_id_proveedor = ? ";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);

            }
            catch(PDOException $e){
                echo 'Error JF-Model-0943: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for update data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function updateProveedor($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_proveedor ".
                         "SET codigo= ?, 
                              nit= ?,
                              razon_social= ?, 
                                direccion= ?, 
                                telefono1= ?, 
                                telefono2= ?, 
                                telefono3= ?, 
                                contacto= ?, 
                                fk_id_rubro= ?,
                                fk_id_ubicacion_geografica= ?, 
                                fecha1= ?, 
                                fecha2= ?,
                                texto1= ?, 
                                texto2 = ?,  ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ?, fk_id_empresa= ?".
                         "WHERE pk_id_proveedor = ? ";

                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0944: '.$e->getMessage();
            }
            return $result;
        }
     // }}}
    }
?>